package com.xmy.cultivate.mapper;

import com.xmy.cultivate.entity.CourseType;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xmy.cultivate.entity.request.SubjectsClassTypeRs;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 课程类别 Mapper 接口
 * </p>
 *
 * @author min
 * @since 2022-07-26
 */
public interface CourseTypeMapper extends BaseMapper<CourseType> {

    @Select("select GROUP_CONCAT(`name`) as type_names from course_type where id in(${classTypeIds})")
    public String getClassTypeNames(@Param("classTypeIds") String classTypeIds);


    /**
     * 按班级获取科目班型
     * @param yearPart
     * @param quarterNum
     * @return
     */
    @Select({"<script>",
            "SELECT",
                      "id,",
                      "subjects_id,",
                      "class_type_id,",
                      "CONCAT( subjects_name, `name` ) AS `name`,",
                      "count ",
                    "FROM",
                      "(",
                      "SELECT",
                        "t1.id,",
                        "t1.subjects_id,",
                        "t1.course_type_id AS class_type_id,",
                        "getSubjectsName ( t1.subjects_id ) AS subjects_name,",
                        "t2.`name`,",
                        "0 AS count ",
                      "FROM",
                        "grade AS t1",
                        "INNER JOIN course_type AS t2 ON t1.course_type_id = t2.id ",
                      "WHERE",
                        "t1.deleted = 0 ",
                        "AND t1.lesson_type = 1 ",
                        "AND t1.deleted = 0 ",
                        "AND t1.year_part = ${yearPart} ",
                        "AND t1.quarter_num = ${quarterNum} ",
                      "GROUP BY",
                        "t1.course_type_id,",
                        "t1.subjects_id ",
                      "ORDER BY",
                        "t1.subjects_id,",
                      "t2.sort ASC ",
                      ") AS t;",
            "</script>"})
    public List<SubjectsClassTypeRs> getSubjectsCourseTypeForGradeList(@Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum);


}
